<template>
	<div v-cloak class="aui-wrapper aui-page__iframe">
		<div class="aui-content__wrapper">
			<div class="aui-content">
				<el-card shadow="never" class="aui-card--fill">
					<div class="mod-lswms__task">
						<el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
							<el-form-item>
								<!-- <el-input v-model="dataForm.tasktype" placeholder="任务类型" clearable></el-input> -->
								<el-select v-model="dataForm.tasktype" size="small" placeholder="任务类型">
									<el-option value="" label="--"> </el-option>
									<el-option v-for="item in tasktypes" :key="item.list" :label="item.listname"
										:value="item.list">
									</el-option>
								</el-select>
							</el-form-item>
							<el-form-item>
								<!-- <el-input v-model="dataForm.status" placeholder="状态" clearable></el-input> -->
								<el-select v-model="dataForm.status" size="small" placeholder="任务类型">
									<el-option value="" label="--"> </el-option>
									<el-option v-for="item in statuss" :key="item.list" :label="item.listname"
										:value="item.list">
									</el-option>
								</el-select>
							</el-form-item>
							<el-form-item>
								<el-input v-model="dataForm.sku"  size="small" placeholder="物料编码" clearable></el-input>
							</el-form-item>
							<el-form-item>
								<el-input v-model="dataForm.descr"  size="small" placeholder="物料名称" clearable></el-input>
							</el-form-item>
							<el-form-item>
								<el-input v-model="dataForm.fromtray"  size="small" placeholder="自箱" clearable></el-input>
							</el-form-item>
							<el-form-item>
								<el-input v-model="dataForm.totray"   size="small" placeholder="至箱" clearable></el-input>
							</el-form-item>
							<el-form-item>
								<el-button  size="small" @click="getDataList()">查询</el-button>
							</el-form-item>
							<!-- <el-form-item>
								<el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>
							</el-form-item> -->
							<el-form-item>
								<el-button type="primary"  size="small" @click="doneHandle()">完成</el-button>
							</el-form-item>
							<!-- <el-form-item>
								<el-button type="danger" @click="deleteHandle()">删除</el-button>
							</el-form-item>
							<el-form-item>
								<el-button type="info" @click="exportHandle()">导出</el-button>
							</el-form-item> -->
						</el-form>
						<el-table v-loading="dataListLoading" :data="dataList" border
							@selection-change="dataListSelectionChangeHandle" @sort-change="dataListSortChangeHandle"
							style="width: 100%;">
							<el-table-column type="selection" header-align="center" align="center" width="50">
							</el-table-column>
							<!-- <el-table-column prop="id" label="序号"  header-align="center"
                                           align="center"></el-table-column> -->
							<el-table-column prop="taskkey" label="任务号" header-align="center" align="center">
							</el-table-column>
							<!-- <el-table-column prop="tasktype" label="任务类型"  header-align="center"
                                           align="center"></el-table-column> -->
							<el-table-column prop="tasktypestr" label="任务类型" header-align="center" align="center">
							</el-table-column>
							<el-table-column prop="priority" label="优先级" header-align="center" align="center">
							</el-table-column>
							<!-- <el-table-column prop="status" label="状态"  header-align="center"
                                           align="center"></el-table-column> -->
							<el-table-column prop="statusstr" label="状态" header-align="center" align="center">
							</el-table-column>
							<el-table-column prop="sku" label="物料编码" header-align="center" align="center">
							</el-table-column>
							<el-table-column prop="descr" label="物料名称" header-align="center" align="center">
							</el-table-column>
							<el-table-column prop="qty" label="数量" header-align="center" align="center">
							</el-table-column>
							<el-table-column prop="fromlocation" label="自库位" header-align="center" align="center">
							</el-table-column>
							<el-table-column prop="tolocation" label="至库位" header-align="center" align="center">
							</el-table-column>
							<el-table-column prop="fromtray" label="自箱" header-align="center" align="center">
							</el-table-column>
							<el-table-column prop="totray" label="至箱" header-align="center" align="center">
							</el-table-column>

							<!--  <el-table-column prop="frombox" label="自箱"  header-align="center"
                                           align="center"></el-table-column>
                                                    <el-table-column prop="tobox" label="至箱"  header-align="center"
                                           align="center"></el-table-column> -->
							<el-table-column prop="fromboxstr" label="自格" header-align="center" align="center">
							</el-table-column>
							<el-table-column prop="toboxstr" label="至格" header-align="center" align="center">
							</el-table-column>
							<el-table-column prop="fromlot" label="自批" header-align="center" align="center">
							</el-table-column>
							<el-table-column prop="tolot" label="至批" header-align="center" align="center">
							</el-table-column>



							<el-table-column type="expand" fixed="right" label="详情">
								<template #default="props">

									<!-- <el-table-column prop="sourcetype" label="来源单类型"  header-align="center"
												align="center"></el-table-column>
												         <el-table-column prop="sourcekey" label="来源单号"  header-align="center"
												align="center"></el-table-column>
												         <el-table-column prop="sourceline" label="来源单行号"  header-align="center"
												align="center"></el-table-column>
												         <el-table-column prop="sourcelinelist" label="来源单记录行号"  header-align="center"
												align="center"></el-table-column>
												         <el-table-column prop="taskno" label="任务流水"  header-align="center"
												align="center"></el-table-column>
												         <el-table-column prop="remark" label="备注"  header-align="center"
												align="center"></el-table-column>
												         <el-table-column prop="sendflag" label="任务下发标志"  header-align="center"
												align="center"></el-table-column>
												         <el-table-column prop="sendtime" label="任务下发时间"  header-align="center"
												align="center"></el-table-column>
												         <el-table-column prop="receivetime" label="任务接收时间"  header-align="center"
												align="center"></el-table-column>
												         <el-table-column prop="adduser" label="创建人"  header-align="center"
												align="center"></el-table-column>
												         <el-table-column prop="addtime" label="创建时间"  header-align="center"
												align="center"></el-table-column>
												         <el-table-column prop="updatuser" label="修改人"  header-align="center"
												align="center"></el-table-column>
												         <el-table-column prop="updatetime" label="修改时间"  header-align="center"
												align="center"></el-table-column> -->


									<el-form label-position="left" inline class="demo-table-expand">
										<el-row>
											<el-col :span="4">
												<el-form-item label="来源单类型:">
													<span>{{ props.row.sourcetype }}</span>
												</el-form-item>
											</el-col>
											<el-col :span="4">
												<el-form-item label="来源单号:">
													<span>{{ props.row.sourcekey }}</span>
												</el-form-item>
											</el-col>
											<el-col :span="4">
												<el-form-item label="来源单行号:">
													<span>{{ props.row.sourceline }}</span>
												</el-form-item>
											</el-col>
											<el-col :span="4">
												<el-form-item label="来源单记录行号:" style="">
													<span>{{ props.row.sourcelinelist }}</span>
												</el-form-item>
											</el-col>
											<el-col :span="4">
												<el-form-item label="任务流水">
													<span>{{ props.row.taskno }}</span>
												</el-form-item>
											</el-col>
											<el-col :span="4">
												<el-form-item label="备注">
													<span>{{ props.row.remark }}</span>
												</el-form-item>
											</el-col>
										</el-row>
										<el-row>
											<el-col :span="4">
												<el-form-item label="任务下发标志:">
													<span>{{ props.row.sendflag}}</span>
												</el-form-item>
											</el-col>
											<el-col :span="4">
												<el-form-item label="任务下发时间:">
													<span>{{ props.row.sendtime}}</span>
												</el-form-item>
											</el-col>
											<el-col :span="4">
												<el-form-item label="任务接收时间:">
													<span>{{ props.row.receivetime}}</span>
												</el-form-item>
											</el-col>

										</el-row>
										<el-row>
											<el-col :span="4">
												<el-form-item label="创建人:">
													<span>{{ props.row.adduser}}</span>
												</el-form-item>
											</el-col>
											<el-col :span="4">
												<el-form-item label="创建时间:">
													<span>{{ props.row.addtime}}</span>
												</el-form-item>
											</el-col>
											<el-col :span="4">
												<el-form-item label="修改人:">
													<span>{{ props.row.updatuser}}</span>
												</el-form-item>
											</el-col>
											<el-col :span="4">
												<el-form-item label="修改时间:">
													<span>{{ props.row.updatetime}}</span>
												</el-form-item>
											</el-col>
											<el-col :span="4">
											</el-col>
											<el-col :span="4">
											</el-col>
										</el-row>
									</el-form>
								</template>
							</el-table-column>
							<!-- 	 <el-table-column label='操作' fixed="right" header-align="center" align="center" width="150">					
                          <template #default="scope">
                              <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
                              <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
                            </template> -->
							<!-- </el-table-column> -->
						</el-table>
						<el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit"
							:total="total" layout="total, sizes, prev, pager, next, jumper"
							@size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle">
						</el-pagination>
						<!-- 弹窗, 新增 / 修改 -->
						<taskAddOrUpdate v-if="addOrUpdateVisible" ref="addOrUpdate" @refresh-data-list="getDataList">
						</taskAddOrUpdate>
					</div>
				</el-card>
			</div>
		</div>
	</div>
</template>

<script>
	import DataList from "@/utils/DataList";
	import {
		ref,
		reactive,
		onMounted,
		nextTick
	} from 'vue';
	import taskAddOrUpdate from "@/components/lswms/task/TaskAddOrUpdate";
	import {
		putTaskDone
	} from "@/network/lswms/task/Task.js"
	import {
		ElMessage,
		ElMessageBox
	} from 'element-plus'
	import {
		getCodeListByCode
	} from "@/network/lswms/base/Codelist.js"
	//import {hasPermission} from "@/utils/hasPermission"
	export default {
		name: "task",

		components: {
			taskAddOrUpdate,
		},

		setup() {
			const {
				dataForm,
				mixinViewModuleOptions,
				getDataList,
				dataList,
				total,
				page,
				limit,
				dataListLoading,
				dataListSelectionChangeHandle,
				dataListSortChangeHandle,
				pageSizeChangeHandle,
				pageCurrentChangeHandle,
				addOrUpdateHandle,
				deleteHandle,
				exportHandle,
				addOrUpdateVisible,
				dataListSelections,
				addOrUpdate
			} = DataList();

			onMounted(() => {
				mixinViewModuleOptions.value.getDataListIsPage = true;
				mixinViewModuleOptions.value.getDataListURL = '/lswms/task/page';
				mixinViewModuleOptions.value.deleteURL = '/lswms/task';
				mixinViewModuleOptions.value.exportURL = '/lswms/task/export';
				mixinViewModuleOptions.value.deleteIsBatchKey = 'id';
				mixinViewModuleOptions.value.deleteIsBatch = true
				if (mixinViewModuleOptions.value.activatedIsNeed) {
					getDataList();
				}
				statusFn();
				tasktypeFn();

			})

			const doneHandle = () => {
				if (dataListSelections.value.length <= 0) {
					return ElMessage({
						message: '请选择任务',
						type: 'warning',
						duration: 1000
					});
				}

				ElMessageBox.confirm('确定完成选择的任务吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(function() {

					let para = dataListSelections.value.map(function(item) {
						return {
							"taskkey": item["taskkey"]
						}
					})
					putTaskDone(para).then(function(res) {
						if (res.code !== 0) {
							return ElMessage.error(res.msg);
						}
						ElMessage({
							message: '操作成功',
							type: 'success',
							duration: 500,
							onClose: function() {
								getDataList();
							}
						});
					}).catch(function() {});

				}).catch(function() {})
			}

			const boxs = ref("");
			const boxsFn = () => {

				getCodeListByCode('BOXLIST').then((res) => {
					if (res.code !== 0) {
						return ElMessage.error(res.msg);
					}
					boxs.value = res.data;
				}).catch((err) => {});
			}

			const tasktypes = ref("");
			const tasktypeFn = () => {

				getCodeListByCode('TASKTYPE').then((res) => {
					if (res.code !== 0) {
						return ElMessage.error(res.msg);
					}
					tasktypes.value = res.data;
				}).catch((err) => {});
			}

			const statuss = ref("");
			const statusFn = () => {

				getCodeListByCode('TASKSTATUS').then((res) => {
					if (res.code !== 0) {
						return ElMessage.error(res.msg);
					}
					statuss.value = res.data;
				}).catch((err) => {});
			}
			return {
				dataForm,
				mixinViewModuleOptions,
				getDataList,
				dataList,
				total,
				page,
				limit,
				dataListLoading,
				dataListSelectionChangeHandle,
				dataListSortChangeHandle,
				pageSizeChangeHandle,
				pageCurrentChangeHandle,
				addOrUpdateHandle,
				deleteHandle,
				exportHandle,
				addOrUpdateVisible,
				dataListSelections,
				addOrUpdate,
				doneHandle,
				tasktypes,
				statuss
			}
		},
		// methods:{
		// 	hasPermission
		// }
	}
</script>

<style scoped>

</style>
